import request from "@/utils/request";
import type {
  GetSpuListParams,
  GetSpuListResponse,
  BaseSaleAttrList,
  GetSpuFormDataItem,
  SpuImageList,
  SpuSaleAttrList,
} from "./model/spuModel";

enum Api {
  spuListUrl = "/admin/product",
  baseSaleAttrListUrl = "/admin/product/baseSaleAttrList",
  saveSpuUrl = "/admin/product/saveSpuInfo",
  delSpuUrl = "/admin/product/deleteSpu",
  updateSpuUrl = "/admin/product/updateSpuInfo",
  getSpuImageListUrl = "/admin/product/spuImageList",
  getSpuSaleAttrListUrl = "/admin/product/spuSaleAttrList",
}
export const spuListApi = ({ page, limit, category3Id }: GetSpuListParams) => {
  return request.get<any, GetSpuListResponse>(
    Api.spuListUrl + `/${page}/${limit}?category3Id=${category3Id}`
  );
};

export const baseSaleAttrListApi = () => {
  return request.get<any, BaseSaleAttrList>(Api.baseSaleAttrListUrl);
};
//添加spu

export const saveSpuApi = (data: GetSpuFormDataItem) => {
  return request.post<any, null>(Api.saveSpuUrl, data);
};

//删除Spu
export const delSpuApi = (id: number) => {
  return request.delete<any, null>(Api.delSpuUrl + `/${id}`);
};
//修改Spu
export const updateSpuApi = (data: GetSpuFormDataItem) => {
  return request.post<any, null>(Api.updateSpuUrl, data);
};

export const getSpuImageListApi = (spuId: number) => {
  return request.get<any, SpuImageList>(Api.getSpuImageListUrl + `/${spuId}`);
};

export const getSpuSaleAttrListApi = (spuId: number) => {
  return request.get<any, SpuSaleAttrList>(
    Api.getSpuSaleAttrListUrl + `/${spuId}`
  );
};
